<?php

define('ACC', true);
require('./include/init.php');
session_start(); 
//print_r($_SESSION);
$userid = $_SESSION['user_id'];

echo '<head><meta charset = "utf-8"></head>';  
//$userid = 26;
 echo '<h2>分类账簿&nbsp|&nbsp<a href = "dashboard.php">返回虚拟公司主页</a></h2><br/>';    

$company = new companymodel();
$companyinfo = $company->getcompanyinfo($userid);
$companyid = $companyinfo['company_id'];
$accounting = new accountingmodel(); 

echo '<h2>公司名称为:' . $companyinfo['company_name'], '&nbsp|&nbsp';
echo '目前所在财年:第' . $companyinfo['company_y'] . '财年', '&nbsp|&nbsp';
echo '目前所在季度:第' . $companyinfo['company_q'] . '季度', '</h2><br/><a href = "generatefinancialreports.php">生成财务报表</a><br/><br/>';

echo '<h3>资产类账户</h3>';
$assetlist =   $accounting ->getaccountlist($companyid, '资产');

foreach($assetlist as $k=>$v){
    $accountid = $v['account_id'];
    $accountname = $v['account_name_ch'];
    $settledbooking = $accounting->getsettledbooking($companyid, $accountid);
    $accountbalance = $accounting->getaccountbalance($companyid, $accountid);
    $postedbooking = $accounting->getpostedbooking($companyid, $accountid);
    if(empty($settledbooking)&&empty($accountbalance)&&empty($postedbooking)){
    continue;
    }
    echo '<h4>&nbsp&nbsp' . $accountname  . '：</h4>';
    foreach($settledbooking as $key=>$value){
        echo '<p>&nbsp&nbsp&nbsp&nbsp&nbsp记账凭证|' . $value['amount'] . '|' . $value['debit_credit'] . '</p>';           
    }
    
    if(!empty($accountbalance)){
        echo '<p style="font-weight:bold;">&nbsp&nbsp&nbsp&nbsp&nbsp余&nbsp&nbsp额|' . $accountbalance['account_balance'] . '|' . $accountbalance['debit_credit'] . '</p>';  
    }

    foreach($postedbooking as $key=>$value){
        echo '<p>&nbsp&nbsp&nbsp&nbsp&nbsp记账凭证|' . $value['amount'] . '|' . $value['debit_credit'] . '</p>';           
    }
    
    if(count($postedbooking)>0){
        echo '&nbsp&nbsp&nbsp&nbsp&nbsp<a href = "account_settle.php?accountid='. $accountid . '" >结账</a>';      
    }
    
} 

echo '<h3>负债类账户</h3>';
$liabilitylist =   $accounting ->getaccountlist($companyid, '负债');

foreach($liabilitylist as $k=>$v){
    $accountid = $v['account_id'];
    $accountname = $v['account_name_ch'];
    $settledbooking = $accounting->getsettledbooking($companyid, $accountid);
    $accountbalance = $accounting->getaccountbalance($companyid, $accountid);
    $postedbooking = $accounting->getpostedbooking($companyid, $accountid);
    if(empty($settledbooking)&&empty($accountbalance)&&empty($postedbooking)){
    continue;
    }
    echo '<h4>&nbsp&nbsp' . $accountname  . '：</h4>';
    foreach($settledbooking as $key=>$value){
        echo '<p>&nbsp&nbsp&nbsp&nbsp&nbsp记账凭证|' . $value['amount'] . '|' . $value['debit_credit'] . '</p>';           
    }
    
    if(!empty($accountbalance)){
        echo '<p style="font-weight:bold;">&nbsp&nbsp&nbsp&nbsp&nbsp余&nbsp&nbsp额|' . $accountbalance['account_balance'] . '|' . $accountbalance['debit_credit'] . '</p>';  
    }

    foreach($postedbooking as $key=>$value){
        echo '<p>&nbsp&nbsp&nbsp&nbsp&nbsp记账凭证|' . $value['amount'] . '|' . $value['debit_credit'] . '</p>';           
    }    
    
    
    if(count($postedbooking)>0){
        echo '&nbsp&nbsp&nbsp&nbsp&nbsp<a href = "">结账</a>';      
    }    
    
} 


echo '<h3>成本类账户</h3>';
$cost =   $accounting ->getaccountlist($companyid, '成本');

foreach($cost as $k=>$v){
    $accountid = $v['account_id'];
    $accountname = $v['account_name_ch'];
    $settledbooking = $accounting->getsettledbooking($companyid, $accountid);
    $accountbalance = $accounting->getaccountbalance($companyid, $accountid);
    $postedbooking = $accounting->getpostedbooking($companyid, $accountid);
    if(empty($settledbooking)&&empty($accountbalance)&&empty($postedbooking)){
    continue;
    }
    echo '<h4>&nbsp&nbsp' . $accountname  . '：</h4>';
    foreach($settledbooking as $key=>$value){
        echo '<p>&nbsp&nbsp&nbsp&nbsp&nbsp记账凭证|' . $value['amount'] . '|' . $value['debit_credit'] . '</p>';           
    }
    
    if(!empty($accountbalance)){
        echo '<p style="font-weight:bold;">&nbsp&nbsp&nbsp&nbsp&nbsp余&nbsp&nbsp额|' . $accountbalance['account_balance'] . '|' . $accountbalance['debit_credit'] . '</p>';  
    }

    foreach($postedbooking as $key=>$value){
        echo '<p>&nbsp&nbsp&nbsp&nbsp&nbsp记账凭证|' . $value['amount'] . '|' . $value['debit_credit'] . '</p>';           
    }    
    
    
    if(count($postedbooking)>0){
        echo '&nbsp&nbsp&nbsp&nbsp&nbsp<a href = "">结账</a>';      
    }    
    
} 



echo '<h3>权益类账户</h3>';
$equitylist =   $accounting ->getaccountlist($companyid, '权益');

foreach($equitylist as $k=>$v){
    $accountid = $v['account_id'];
    $accountname = $v['account_name_ch'];
    $settledbooking = $accounting->getsettledbooking($companyid, $accountid);
    $accountbalance = $accounting->getaccountbalance($companyid, $accountid);
    $postedbooking = $accounting->getpostedbooking($companyid, $accountid);
    if(empty($settledbooking)&&empty($accountbalance)&&empty($postedbooking)){
    continue;
    }
    echo '<h4>&nbsp&nbsp' . $accountname  . '：</h4>';
    foreach($settledbooking as $key=>$value){
        echo '<p>&nbsp&nbsp&nbsp&nbsp&nbsp记账凭证|' . $value['amount'] . '|' . $value['debit_credit'] . '</p>';           
    }
    
    if(!empty($accountbalance)){
        echo '<p style="font-weight:bold;">&nbsp&nbsp&nbsp&nbsp&nbsp余&nbsp&nbsp额|' . $accountbalance['account_balance'] . '|' . $accountbalance['debit_credit'] . '</p>';  
    }

    foreach($postedbooking as $key=>$value){
        echo '<p>&nbsp&nbsp&nbsp&nbsp&nbsp记账凭证|' . $value['amount'] . '|' . $value['debit_credit'] . '</p>';           
    }    
    
    
    if(count($postedbooking)>0){
        echo '&nbsp&nbsp&nbsp&nbsp&nbsp<a href = "">结账</a>';      
    }    
    
}  


echo '<h3>损益类账户</h3>';
$pnllist =   $accounting ->getaccountlist($companyid, '损益');

foreach($pnllist as $k=>$v){
    $accountid = $v['account_id'];
    $accountname = $v['account_name_ch'];
    $settledbooking = $accounting->getsettledbooking($companyid, $accountid);
    $accountbalance = $accounting->getaccountbalance($companyid, $accountid);
    $postedbooking = $accounting->getpostedbooking($companyid, $accountid);
    if(empty($settledbooking)&&empty($accountbalance)&&empty($postedbooking)){
    continue;
    }
    echo '<h4>&nbsp&nbsp' . $accountname  . '：</h4>';
    foreach($settledbooking as $key=>$value){
        echo '<p>&nbsp&nbsp&nbsp&nbsp&nbsp记账凭证|' . $value['amount'] . '|' . $value['debit_credit'] . '</p>';           
    }
    
    if(!empty($accountbalance)){
        echo '<p style="font-weight:bold;">&nbsp&nbsp&nbsp&nbsp&nbsp余&nbsp&nbsp额|' . $accountbalance['account_balance'] . '|' . $accountbalance['debit_credit'] . '</p>';  
    }

    foreach($postedbooking as $key=>$value){
        echo '<p>&nbsp&nbsp&nbsp&nbsp&nbsp记账凭证|' . $value['amount'] . '|' . $value['debit_credit'] . '</p>';           
    }    
    
    
    if(count($postedbooking)>0){
        echo '&nbsp&nbsp&nbsp&nbsp&nbsp<a href = "">结账</a>';      
    }    
    
} 


echo '<h3>共同类账户</h3>';
$commonlist =   $accounting ->getaccountlist($companyid, '共同');

foreach($commonlist as $k=>$v){
    $accountid = $v['account_id'];
    $accountname = $v['account_name_ch'];
    $settledbooking = $accounting->getsettledbooking($companyid, $accountid);
    $accountbalance = $accounting->getaccountbalance($companyid, $accountid);
    $postedbooking = $accounting->getpostedbooking($companyid, $accountid);
    if(empty($settledbooking)&&empty($accountbalance)&&empty($postedbooking)){
    continue;
    }
    echo '<h4>&nbsp&nbsp' . $accountname  . '：</h4>';
    foreach($settledbooking as $key=>$value){
        echo '<p>&nbsp&nbsp&nbsp&nbsp&nbsp记账凭证|' . $value['amount'] . '|' . $value['debit_credit'] . '</p>';           
    }
    
    if(!empty($accountbalance)){
        echo '<p style="font-weight:bold;">&nbsp&nbsp&nbsp&nbsp&nbsp余&nbsp&nbsp额|' . $accountbalance['account_balance'] . '|' . $accountbalance['debit_credit'] . '</p>';  
    }

    foreach($postedbooking as $key=>$value){
        echo '<p>&nbsp&nbsp&nbsp&nbsp&nbsp记账凭证|' . $value['amount'] . '|' . $value['debit_credit'] . '</p>';           
    }    
    
    
    if(count($postedbooking)>0){
        echo '&nbsp&nbsp&nbsp&nbsp&nbsp<a href = "">结账</a>';      
    }    
    
}     



?>
